home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / MUI / DEFTV13.LHA / Deft II / Sources / Arexx.em < prev    next >
Encoding:
Text File  |  1994-09-02  |  10.9 KB  |  335 lines

  1. OPT MODULE
  2.  
  3.  
  4. ->*****
  5. ->** External modules
  6. ->*****
  7. MODULE 'muimaster' , 'libraries/mui'
  8. MODULE 'tools/boopsi'
  9. MODULE 'utility/tagitem' , 'utility/hooks'
  10. MODULE 'tools/installhook'
  11.  
  12. MODULE '*Locale'
  13. MODULE '*Defs'
  14. MODULE '*Errors'
  15. MODULE '*GUI_MUIB'
  16. MODULE '*Work'
  17. MODULE '*PrefsFile'
  18. MODULE '*Paths'
  19. MODULE '*DefaultTools'
  20.  
  21.  
  22. ->*****
  23. ->** Global variables
  24. ->*****
  25. EXPORT DEF deftII                    :    PTR TO obj_app
  26. EXPORT DEF cat                        :    PTR TO catalog_DeftII
  27. EXPORT DEF modified                    :    LONG
  28. EXPORT DEF current_edited_path        :    LONG
  29. EXPORT DEF current_edited_def_tool    :    LONG
  30.  
  31.  
  32. /********************************************************************************************************/
  33. /* Initializes the object which gives arexx information needed for the MUI application at creation time */
  34. /********************************************************************************************************/
  35. EXPORT PROC init_arexx()
  36.  
  37.     DEF arexx : PTR TO obj_arexx
  38.     DEF arexx_commands : PTR TO mui_command
  39.     DEF number_paths_hook            :    PTR TO hook
  40.     DEF number_default_tools_hook    :    PTR TO hook
  41.     DEF add_path_hook                :    PTR TO hook
  42.     DEF add_default_tool_hook        :    PTR TO hook
  43.     DEF delete_path_hook            :    PTR TO hook
  44.     DEF delete_default_tool_hook    :    PTR TO hook
  45.     DEF get_path_hook                :    PTR TO hook
  46.     DEF get_old_default_tool_hook    :    PTR TO hook
  47.     DEF get_new_default_tool_hook    :    PTR TO hook
  48.     DEF save_prefs_hook                :    PTR TO hook
  49.     DEF go_hook                        :    PTR TO hook
  50.     DEF loose_modifications_hook    :    PTR TO hook
  51.  
  52.     NEW    arexx , arexx_commands[ 13 ] ,
  53.         number_paths_hook            ,
  54.         number_default_tools_hook    ,
  55.         add_path_hook                ,
  56.         add_default_tool_hook        ,
  57.         delete_path_hook            ,
  58.         delete_default_tool_hook    ,
  59.         get_path_hook                ,
  60.         get_old_default_tool_hook    ,
  61.         get_new_default_tool_hook    ,
  62.         save_prefs_hook                ,
  63.         go_hook                        ,
  64.         loose_modifications_hook
  65.  
  66.     installhook(    number_paths_hook            ,     {number_paths}                )
  67.     installhook(    number_default_tools_hook    ,    {number_default_tools}        )
  68.     installhook(    add_path_hook                ,    {arexx_add_path}            )
  69.     installhook(    add_default_tool_hook        ,    {arexx_add_default_tool}    )
  70.     installhook(    delete_path_hook            ,    {arexx_delete_path}            )
  71.     installhook(    delete_default_tool_hook    ,    {arexx_delete_default_tool}    )
  72.     installhook(    get_path_hook                ,    {get_path}                    )
  73.     installhook(    get_old_default_tool_hook    ,    {get_old_default_tool}        )
  74.     installhook(    get_new_default_tool_hook    ,    {get_new_default_tool}        )
  75.     installhook(    save_prefs_hook                ,    {arexx_save_prefs}            )
  76.     installhook(    go_hook                        ,    {arexx_go}                    )
  77.     installhook(    loose_modifications_hook    ,    {loose_modifications}        )
  78.  
  79.     arexx_commands := [    'number_paths' , '' , 0 , number_paths_hook ,
  80.                                                                             NIL , NIL , NIL , NIL ,NIL ,
  81.                         'number_default_tools' , '' , 0 , number_default_tools_hook ,
  82.                                                                             NIL , NIL , NIL , NIL ,NIL ,
  83.                         'add_path' , 'PATH/A' , 1 , add_path_hook ,
  84.                                                                             NIL , NIL , NIL , NIL ,NIL ,
  85.                         'add_default_tool' , 'OLD/A,NEW/A' , 2 , add_default_tool_hook ,
  86.                                                                             NIL , NIL , NIL , NIL ,NIL ,
  87.                         'delete_path' , 'PATH/N/A' , 1 , delete_path_hook ,
  88.                                                                             NIL , NIL , NIL , NIL ,NIL ,
  89.                         'delete_default_tool' , 'DEFAULT_TOOL=DT/N/A' , 1 , delete_default_tool_hook ,
  90.                                                                             NIL , NIL , NIL , NIL ,NIL ,
  91.                         'get_path' , 'PATH/N/A' , 1 , get_path_hook ,
  92.                                                                             NIL , NIL , NIL , NIL ,NIL ,
  93.                         'get_old_default_tool' , 'OLD_DEFAULT_TOOL=ODT/N/A' , 1 , get_old_default_tool_hook ,
  94.                                                                             NIL , NIL , NIL , NIL ,NIL ,
  95.                         'get_new_default_tool' , 'NEW_DEFAULT_TOOL=NDT/N/A' , 1 , get_new_default_tool_hook ,
  96.                                                                             NIL , NIL , NIL , NIL ,NIL ,
  97.                         'save_prefs' , '' , 0 , save_prefs_hook ,
  98.                                                                             NIL , NIL , NIL , NIL ,NIL ,
  99.                         'go' , '' , 0 , go_hook ,
  100.                                                                             NIL , NIL , NIL , NIL ,NIL ,
  101.                         'loose_modifications' , '' , 0 , loose_modifications_hook ,
  102.                                                                             NIL , NIL , NIL , NIL ,NIL ,
  103.                         NIL , NIL , NIL , NIL ,
  104.                                                                             NIL , NIL , NIL , NIL ,NIL ] : mui_command
  105.  
  106.     arexx.commands := arexx_commands
  107.     installhook( arexx.error , {arexx_error} )
  108.  
  109. ENDPROC arexx
  110.  
  111.  
  112. /*************************************************************************/
  113. /* Arexx hook function which returns the number of paths in the listview */
  114. /*************************************************************************/
  115. PROC number_paths()
  116.  
  117.     DEF number_entries
  118.     DEF return_string[ 10 ] : STRING
  119.  
  120.     get( deftII.lv_paths , MUIA_List_Entries , {number_entries} )
  121.     set( deftII.app , MUIA_Application_RexxString , StringF( return_string , '\d' , number_entries ) )
  122.  
  123. ENDPROC 0
  124.  
  125.  
  126. /*********************************************************************************/
  127. /* Arexx hook function which returns the number of default_tools in the listview */
  128. /*********************************************************************************/
  129. PROC number_default_tools()
  130.  
  131.     DEF number_entries
  132.     DEF return_string[ 10 ] : STRING
  133.  
  134.     get( deftII.lv_default_tools , MUIA_List_Entries , {number_entries} )
  135.     set( deftII.app , MUIA_Application_RexxString , StringF( return_string , '\d' , number_entries ) )
  136.  
  137. ENDPROC 0
  138.  
  139.  
  140. /*********************************************************/
  141. /* Arexx hook function to add a path inside the listview */
  142. /*********************************************************/
  143. PROC arexx_add_path( hook , obj , arg_array : PTR TO LONG )
  144.  
  145.     set( deftII.wi_main , MUIA_Window_ActiveObject , deftII.lv_paths )
  146.  
  147. ENDPROC add_path( arg_array[] )
  148.  
  149.  
  150. /*****************************************************************/
  151. /* Arexx hook function to add a default tool inside the listview */
  152. /*****************************************************************/
  153. PROC arexx_add_default_tool( hook , obj , arg_array : PTR TO LONG )
  154.  
  155.     set( deftII.wi_main , MUIA_Window_ActiveObject , deftII.lv_default_tools )
  156.  
  157. ENDPROC add_default_tool( arg_array[] , arg_array[ 1 ] )
  158.  
  159.  
  160. /************************************************************/
  161. /* Arexx hook function to delete a path inside the listview */
  162. /************************************************************/
  163. PROC arexx_delete_path( hook , obj , arg_array : PTR TO LONG )
  164.  
  165.     DEF entry , number_entries , return = 0
  166.  
  167.     entry := Long( arg_array[] )
  168.     get( deftII.lv_paths , MUIA_List_Entries , {number_entries} )
  169.  
  170.     IF ( entry >= 0 ) AND ( entry < number_entries )
  171.  
  172.         set( deftII.lv_paths , MUIA_List_Quiet , MUI_TRUE )
  173.         domethod( deftII.lv_paths , [ MUIM_List_Remove , entry ] )
  174.         set( deftII.lv_paths , MUIA_List_Quiet , FALSE )
  175.  
  176.     ELSE
  177.  
  178.         return := 10
  179.  
  180.     ENDIF
  181.  
  182.     current_edited_path := NO_CURRENT_EDITED_PATH
  183.     set( deftII.stR_PA_path , MUIA_String_Contents , '' )
  184.  
  185.     set( deftII.wi_main , MUIA_Window_ActiveObject , deftII.lv_paths )
  186.  
  187. ENDPROC return
  188.  
  189.  
  190. /********************************************************************/
  191. /* Arexx hook function to delete a default tool inside the listview */
  192. /********************************************************************/
  193. PROC arexx_delete_default_tool( hook , obj , arg_array : PTR TO LONG )
  194.  
  195.     DEF entry , number_entries , return = 0
  196.  
  197.     entry := Long( arg_array[] )
  198.     get( deftII.lv_default_tools , MUIA_List_Entries , {number_entries} )
  199.  
  200.     IF ( entry >= 0 ) AND ( entry < number_entries )
  201.  
  202.         set( deftII.lv_default_tools , MUIA_List_Quiet , MUI_TRUE )
  203.         domethod( deftII.lv_default_tools , [ MUIM_List_Remove , entry ] )
  204.         set( deftII.lv_default_tools , MUIA_List_Quiet , FALSE )
  205.  
  206.     ELSE
  207.  
  208.         return := 10
  209.  
  210.     ENDIF
  211.  
  212.     current_edited_def_tool := NO_CURRENT_EDITED_DEF_TOOL
  213.     set( deftII.stR_old_def_tool , MUIA_String_Contents , '' )
  214.     set( deftII.stR_PO_new_def_tool , MUIA_String_Contents , '' )
  215.  
  216.     set( deftII.wi_main , MUIA_Window_ActiveObject , deftII.lv_default_tools )
  217.  
  218. ENDPROC return
  219.  
  220.  
  221. /*******************************************************/
  222. /* Arexx hook function to get from the listview a path */
  223. /*******************************************************/
  224. PROC get_path( hook , obj , arg_array : PTR TO LONG )
  225.  
  226.     DEF entry_number , entry : PTR TO CHAR
  227.     DEF number_entries , return = 0
  228.  
  229.     entry_number := Long( arg_array[] )
  230.     get( deftII.lv_paths , MUIA_List_Entries , {number_entries} )
  231.  
  232.     IF ( entry_number >= 0 ) AND ( entry_number < number_entries )
  233.  
  234.         domethod( deftII.lv_paths , [ MUIM_List_GetEntry , entry_number , {entry} ] )
  235.         set( deftII.app , MUIA_Application_RexxString , entry )
  236.  
  237.     ELSE
  238.  
  239.         return := 10
  240.  
  241.     ENDIF
  242.  
  243. ENDPROC return
  244.  
  245.  
  246. /********************************************************************/
  247. /* Arexx hook function to get from the listview an old default tool */
  248. /********************************************************************/
  249. PROC get_old_default_tool( hook , obj , arg_array : PTR TO LONG )
  250.  
  251.     DEF entry_number , entry : PTR TO default_tool
  252.     DEF number_entries , return = 0
  253.  
  254.     entry_number := Long( arg_array[] )
  255.     get( deftII.lv_default_tools , MUIA_List_Entries , {number_entries} )
  256.  
  257.     IF ( entry_number >= 0 ) AND ( entry_number < number_entries )
  258.  
  259.         domethod( deftII.lv_default_tools , [ MUIM_List_GetEntry , entry_number , {entry} ] )
  260.         set( deftII.app , MUIA_Application_RexxString , entry.old )
  261.  
  262.     ELSE
  263.  
  264.         return := 10
  265.  
  266.     ENDIF
  267.  
  268. ENDPROC return
  269.  
  270.  
  271. /*******************************************************************/
  272. /* Arexx hook function to get from the listview a new default tool */
  273. /*******************************************************************/
  274. PROC get_new_default_tool( hook , obj , arg_array : PTR TO LONG )
  275.  
  276.     DEF entry_number , entry : PTR TO default_tool
  277.     DEF number_entries , return = 0
  278.  
  279.     entry_number := Long( arg_array[] )
  280.     get( deftII.lv_default_tools , MUIA_List_Entries , {number_entries} )
  281.  
  282.     IF ( entry_number >= 0 ) AND ( entry_number < number_entries )
  283.  
  284.         domethod( deftII.lv_default_tools , [ MUIM_List_GetEntry , entry_number , {entry} ] )
  285.         set( deftII.app , MUIA_Application_RexxString , entry.new )
  286.  
  287.     ELSE
  288.  
  289.         return := 10
  290.  
  291.     ENDIF
  292.  
  293. ENDPROC return
  294.  
  295.  
  296. /*********************************************/
  297. /* Saves the preferences file from the Arexx */
  298. /*********************************************/
  299. PROC arexx_save_prefs() IS save_prefs( FALSE )
  300.  
  301.  
  302. /*************************************************************************/
  303. /* The function which runs the icon default tool replacements from Arexx */
  304. /*************************************************************************/
  305. PROC arexx_go()
  306.  
  307.     set( deftII.gr_paths , MUIA_Disabled , MUI_TRUE )
  308.     set( deftII.gr_default_tools , MUIA_Disabled , MUI_TRUE )
  309.     set( deftII.bt_go , MUIA_Disabled , MUI_TRUE )
  310.     set( deftII.bt_save_prefs , MUIA_Disabled , MUI_TRUE )
  311.     set( deftII.bt_about , MUIA_Disabled , MUI_TRUE )
  312.     set( deftII.bt_quit , MUIA_Disabled , MUI_TRUE )
  313.  
  314. ENDPROC go( FALSE )
  315.  
  316.  
  317. /********************************************************************/
  318. /* Hook function to loose any modification track of the preferences */
  319. /********************************************************************/
  320. PROC loose_modifications()
  321.  
  322.     modified := FALSE
  323.  
  324. ENDPROC 0
  325.  
  326.  
  327. /*********************************************************************************/
  328. /* This hook function is called when an unknown arexx command is sent to Deft II */
  329. /*********************************************************************************/
  330. PROC arexx_error()
  331.  
  332.     deftII_error( get_string( cat.msg_Unknown_Arexx_Command ) )
  333.  
  334. ENDPROC 100
  335.